package org.feiye.studyday27.fanshe;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class TestStudent {

	public static void main(String[] args) throws Exception {
		Class c = Student.class;
		System.out.println("学生类的所有构造方法如下：");
		Constructor[] d = c.getDeclaredConstructors();
		for (Constructor constructor : d) {
			System.out.println(constructor);
		}
		System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>");
		Constructor cc = c.getDeclaredConstructor(String.class, Sex.class, int.class);
		cc.setAccessible(true);// 去掉访问限制
		Student st = (Student) cc.newInstance("蒋伟", Sex.人妖, 32);
		System.out.println(st);
		System.out.println("<<<<<<<<<<<<<<>>>>>>>>>>");
		Field sname = c.getDeclaredField("name");
		sname.setAccessible(true);
		sname.set(st, "胡军");
		System.out.println(st);
		System.out.println("<<<<<<<<<<<<<<>>>>>>>>>>");
		Method me = c.getDeclaredMethod("setAge", int.class);
		me.invoke(st, 13);
		System.out.println(st);
	}

}
